package com.intexh.quickandroid.module.chat.ChatManager;

import android.content.Context;

import com.intexh.quickandroid.module.chat.bean.ChatMessage;
import com.intexh.quickandroid.module.chat.ui.ImageShowActivity;

import java.util.List;

public enum ChatController {
	INSTANCE;

    public void showImage(Context context, String url, List<ChatMessage> messageList) {
//        LogCatUtil.e("gaohua","url:"+url);
        StringBuilder sb = new StringBuilder();
        int imagePosition = 0;
        int currentImagePosition=0;
        for (ChatMessage message : messageList) {
            if (message.getType() == 2) {
                if (message.getContent() != null) {
                    if (message.getContent().startsWith("http")) {
                        sb.append(message.getContent()).append(",");
                        if(url.equals(message.getContent())){
                            currentImagePosition=imagePosition;
                        }
                        imagePosition++;
                    }
                } else if (message.getLocalUrl() != null) {
                    sb.append("file:///").append(message.getLocalUrl()).append(",");
                    if(url.equals(message.getLocalUrl())){
                        currentImagePosition=imagePosition;
                    }
                    imagePosition++;
                }

            } 
        }
        if (sb.length() > 1) {
            String[] urls = sb.substring(0, sb.length() - 1).split(",");
            for (String path  : urls) {
//                LogCatUtil.e("gaohua","path："+path);
            }
            ImageShowActivity.startActivity(context, urls,currentImagePosition);
        }
    }


}
